const { createProxyMiddleware } = require('http-proxy-middleware');

const simpleRequestLogger = (proxyServer, options) => {
  proxyServer.on('proxyReq', (proxyReq, req, res) => {
    console.log(`[HPM] [${req.method}] ${req.url}`); // outputs: [HPM] GET /users
  });
}

module.exports = function (app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'https://platform.solidhub.cn/yh',
      changeOrigin: true,
      plugins: [simpleRequestLogger],
    })
  );
};